package acm.同步赛4;

import java.util.Scanner;

public class K {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int i = sc.nextInt();
        while (i-- > 0) {
            System.out.println(fun(sc.nextLong()));
        }
    }
    public static int fun(long n){
        return (int) (Math.log(n)/Math.log(3)+n%3);
    }
}
